package com.guawazi.utils;

public class Utils {
    /**
     * 转化月日年
     */
    public static String transformDate(String srcStr) {
        StringBuilder sb = new StringBuilder(srcStr);
        String monthStr = sb.substring(2, 4);
        String dayStr = sb.substring(0, 2);
        String yearStr = sb.substring(4, srcStr.length());

        return monthStr + "/" + dayStr + "/" + yearStr;
    }

    /**
     * 转化经纬度
     */
    public static String transformLocation(String locStr) {
        StringBuilder sb = new StringBuilder(locStr);
        String end = sb.charAt(locStr.length() - 1) + "";
        switch (end) {
            case "N": {
                StringBuilder srcStr = new StringBuilder(sb.deleteCharAt(locStr.length() - 1).toString());
                String du = srcStr.substring(0, 2);
                String fen = srcStr.substring(2, 4);
                String miao = new StringBuilder(srcStr.substring(4, srcStr.length())).insert(2, '.').toString();

                Double result = Double.valueOf(du) + Double.valueOf(fen) / 60 + Double.valueOf(miao) / 3600;
                return result + "";
            }
            case "S": {
                StringBuilder srcStr = new StringBuilder(sb.deleteCharAt(locStr.length() - 1).toString());
                String du = srcStr.substring(0, 2);
                String fen = srcStr.substring(2, 4);
                String miao = new StringBuilder(srcStr.substring(4, srcStr.length())).insert(2, '.').toString();

                Double result = Double.valueOf(du) + Double.valueOf(fen) / 60 + Double.valueOf(miao) / 3600;
                return "-" + result;
            }
            case "E": {
                StringBuilder srcStr = new StringBuilder(sb.deleteCharAt(locStr.length() - 1).toString());
                String du = srcStr.substring(0, 3);
                String fen = srcStr.substring(3, 5);
                String miao = new StringBuilder(srcStr.substring(5, srcStr.length())).insert(2, '.').toString();

                Double result = Double.valueOf(du) + Double.valueOf(fen) / 60 + Double.valueOf(miao) / 3600;
                return result + "";
            }
            case "W": {
                StringBuilder srcStr = new StringBuilder(sb.deleteCharAt(locStr.length() - 1).toString());
                String du = srcStr.substring(0, 3);
                String fen = srcStr.substring(3, 5);
                String miao = new StringBuilder(srcStr.substring(5, srcStr.length())).insert(2, '.').toString();

                Double result = Double.valueOf(du) + Double.valueOf(fen) / 60 + Double.valueOf(miao) / 3600;
                return "-" + result;
            }
        }

        return locStr;
    }

    public static String adddufenmiao(String locStr) {
        StringBuilder sb = new StringBuilder(locStr);
        String end = sb.charAt(locStr.length() - 1) + "";
        switch (end) {
            case "N": {
                StringBuilder srcStr = new StringBuilder(sb.deleteCharAt(locStr.length() - 1).toString());
                String du = srcStr.substring(0, 2);
                String fen = srcStr.substring(2, 4);
                String miao = new StringBuilder(srcStr.substring(4, srcStr.length())).insert(2, '.').toString();

                String result = du + "°" + fen + "′" + miao + "″N";
                return result;
            }
            case "S": {
                StringBuilder srcStr = new StringBuilder(sb.deleteCharAt(locStr.length() - 1).toString());
                String du = srcStr.substring(0, 2);
                String fen = srcStr.substring(2, 4);
                String miao = new StringBuilder(srcStr.substring(4, srcStr.length())).insert(2, '.').toString();

                String result = "-" + du + "°" + fen + "′" + miao + "″S";
                return result;
            }
            case "E": {
                StringBuilder srcStr = new StringBuilder(sb.deleteCharAt(locStr.length() - 1).toString());
                String du = srcStr.substring(0, 3);
                String fen = srcStr.substring(3, 5);
                String miao = new StringBuilder(srcStr.substring(5, srcStr.length())).insert(2, '.').toString();

                String result = du + "°" + fen + "′" + miao + "″E";
                return result;
            }
            case "W": {
                StringBuilder srcStr = new StringBuilder(sb.deleteCharAt(locStr.length() - 1).toString());
                String du = srcStr.substring(0, 3);
                String fen = srcStr.substring(3, 5);
                String miao = new StringBuilder(srcStr.substring(5, srcStr.length())).insert(2, '.').toString();

                String result = "-" + du + "°" + fen + "′" + miao + "″W";
                return result;
            }
        }

        return locStr;
    }
}
